import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardDemo {
    public static final String[] suits={"♥","♠","♣","♦"};
    public static List<Card> buyCards() {
        List<Card> cardlist=new ArrayList<>();
        for(int i=0;i< suits.length;i++){
            for(int j=1;j<=13;j++){
                Card card=new Card(j,suits[i]);//这一步别搞混了
                cardlist.add(card);
            }
        }
        return cardlist;
    }

    public static void shengchengsuijishu(List<Card> cardList) {
        for(int i=cardList.size()-1;i>0;i--){//从最后一个开始
            Random random=new Random();
            int index=random.nextInt(i);//如果是51.就和[0,51)之间的交换
            swap(cardList,i,index);
        }
    }

    public static void swap(List<Card> cardList,int x,int y ) {
        //tmp=x;
        Card tmp=cardList.get(x);
        //x=y;
        cardList.set(x,cardList.get(y));//cardList.get(y)才是y位置上的元素
        //y=tmp
        cardList.set(y,tmp);

    }
    public static void main(String[] args) {
        List<Card> cardList=CardDemo.buyCards();
        System.out.println(cardList);
        shengchengsuijishu(cardList);
        System.out.println("洗牌后");
        System.out.println(cardList);
        System.out.println("开始每个人轮流发5张牌");
        List<Card> hand0=new ArrayList<>();
        List<Card> hand1=new ArrayList<>();
        List<Card> hand2=new ArrayList<>();
        List<List<Card>> hands=new ArrayList<>();
        hands.add(hand0);
        hands.add(hand1);
        hands.add(hand2);//经常搞忘，要记住，初始化后要及时add回去
        for(int i=0;i<5;i++){
            for(int j=0;j<3;j++){
                Card card=cardList.remove(0);//把cardList中去掉的牌给card
                hands.get(j).add(card);
            }
        }
        System.out.println("第一个人的牌");
        System.out.println(hand0);
        System.out.println("第二个人的牌");
        System.out.println(hand1);
        System.out.println("第三个人的牌");
        System.out.println(hand2);
        System.out.println("剩下的牌");
        System.out.println(cardList);





    }
}
